<template>
  <div id="teamPage">
    <van-search v-model="searchText" placeholder="搜索我加入的队伍" @search="onSearch" />
    <van-tabs v-model:active="active" @change="onTabChange">
      <van-tab title="公开" name="public"/>
      <van-tab title="私密" name="private"/>
    </van-tabs>
    <team-card-list :teamList = "teamList"/>
    <van-empty v-if="teamList?.length < 1" description="数据为空"/>
  </div>
</template>

<script setup lang="ts">
import {useRouter} from "vue-router";
import TeamCardList from "../components/TeamCardList.vue";
import {onMounted, ref} from "vue";
import myAxios from "../plugins/myAxios";
import {showFailToast, Toast} from "vant";
import 'vant/es/toast/style';
const router = useRouter();
const searchText = ref('');
const teamList = ref([]);
const searchTexts = ref('');
const active = ref('public')
/**
 * 切换查询状态
 */
const onTabChange = (name) =>{
  //查公开
  if(name == 'public'){
    listTeam(searchTexts.value,0);
  }else{
    //查加密
    listTeam(searchTexts.value,2);
  }

  //不分公开加密

}
/**
 * 搜索队伍
 * @param val
 * @returns {Promise<void>}
 */
const listTeam = async (val = '',status=0 ) => {
  const res = await myAxios.get("/team/list/my/join", {
    params: {
      searchText: val,
      pageNum: 1,
      status
    },
  });
  if (res?.code === 0) {
    teamList.value = res.data;

  } else {
    showFailToast('加载队伍失败，请刷新重试');
  }
}


// 页面加载时只触发一次
onMounted( () => {
  listTeam();
})

const onSearch = (val) => {
  listTeam(val);
};

</script>

<style scoped>
#teamPage {

}
</style>
